import { loginByUsername, getUserInfo } from "@/api/login";
import { getToken, setToken, removeToken } from "@/utils/auth";

const user = {
    state: {
        token: getToken()
    },
    mutations: {
        SET_TOKEN: (state, token) => {
            state.token = token;
        }
    },
    actions: {
        // 用户名登录
        async LoginByUsername({ commit }, userInfo) {
            const username = userInfo.username.trim();
            /*
                {
                    "access_token": "968f2804-f1f1-4ca0-a8a1-97ea1c1d3622",
                    "token_type": "bearer",
                    "refresh_token": "d0a10ebb-1517-4844-b962-59dc4658e925",
                    "expires_in": 7199,
                    "scope": "select"
                }
             */
            const data = await loginByUsername(username, userInfo.password);
            commit("SET_TOKEN", data.access_token);
            setToken(data);
        }
    },

};
export default user;